package dev.curso.android.httpclient;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class RegistroAcitivity extends Activity implements OnClickListener{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_registro);
		((Button)findViewById(R.id.registroReg)).setOnClickListener(this);
	}

	public void onClick(View v) {
		String user = ((EditText)findViewById(R.id.usuarioReg)).getText().toString();
		String password = ((EditText)findViewById(R.id.passwordReg)).getText().toString();
		String email = ((EditText)findViewById(R.id.emailReg)).getText().toString();
		FuncionesUsuario funciones = new FuncionesUsuario();
		JSONObject json = funciones.registrarUsuario(user, email, password);
		try {
			if(json.getString("success")!=null){
				String res = json.getString("success");
				if(Integer.parseInt(res)==1){
					finish();
				}else{
					Toast.makeText(this, "Fallo en el registro", Toast.LENGTH_SHORT).show();
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
}
